home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP04 / LINEDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.0 KB  |  92 lines

  1. /*--------------------------------------------------
  2.    LINEDEMO.C -- Line-Drawing Demonstration Program
  3.                  (c) Charles Petzold, 1996
  4.   --------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12.      {
  13.      static char szAppName[] = "LineDemo" ;
  14.      HWND        hwnd ;
  15.      MSG         msg ;
  16.      WNDCLASSEX  wndclass ;
  17.  
  18.      wndclass.cbSize        = sizeof (wndclass) ;
  19.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  20.      wndclass.lpfnWndProc   = WndProc ;
  21.      wndclass.cbClsExtra    = 0 ;
  22.      wndclass.cbWndExtra    = 0 ;
  23.      wndclass.hInstance     = hInstance ;
  24.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  25.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  26.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  27.      wndclass.lpszMenuName  = NULL ;
  28.      wndclass.lpszClassName = szAppName ;
  29.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  30.  
  31.      RegisterClassEx (&wndclass) ;
  32.  
  33.      hwnd = CreateWindow (szAppName, "Line Demonstration",
  34.                           WS_OVERLAPPEDWINDOW,
  35.                           CW_USEDEFAULT, CW_USEDEFAULT,
  36.                           CW_USEDEFAULT, CW_USEDEFAULT,
  37.                           NULL, NULL, hInstance, NULL) ;
  38.  
  39.      ShowWindow (hwnd, iCmdShow) ;
  40.      UpdateWindow (hwnd) ;
  41.  
  42.      while (GetMessage (&msg, NULL, 0, 0))
  43.           {
  44.           TranslateMessage (&msg) ;
  45.           DispatchMessage (&msg) ;
  46.           }
  47.      return msg.wParam ;
  48.      }
  49.  
  50. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  51.      {
  52.      static int  cxClient, cyClient ;
  53.      HDC         hdc ;
  54.      PAINTSTRUCT ps ;
  55.  
  56.      switch (iMsg)
  57.           {
  58.           case WM_SIZE:
  59.                cxClient = LOWORD (lParam) ;
  60.                cyClient = HIWORD (lParam) ;
  61.                return 0 ;
  62.  
  63.           case WM_PAINT:
  64.                hdc = BeginPaint (hwnd, &ps) ;
  65.  
  66.                Rectangle (hdc,     cxClient / 8,     cyClient / 8,
  67.                                7 * cxClient / 8, 7 * cyClient / 8) ;
  68.  
  69.                MoveToEx  (hdc,        0,        0, NULL) ;
  70.                LineTo    (hdc, cxClient, cyClient) ;
  71.  
  72.                MoveToEx  (hdc,        0, cyClient, NULL) ;
  73.                LineTo    (hdc, cxClient,        0) ;
  74.  
  75.                Ellipse   (hdc,     cxClient / 8,     cyClient / 8,
  76.                                7 * cxClient / 8, 7 * cyClient / 8) ;
  77.  
  78.                RoundRect (hdc,     cxClient / 4,     cyClient / 4,
  79.                                3 * cxClient / 4, 3 * cyClient / 4,
  80.                                    cxClient / 4,     cyClient / 4) ;
  81.  
  82.                EndPaint (hwnd, &ps) ;
  83.                return 0 ;
  84.  
  85.           case WM_DESTROY:
  86.                PostQuitMessage (0) ;
  87.                return 0 ;
  88.           }
  89.  
  90.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  91.      }
  92.